$(document).ready(function() {
    entryCardCost.init();

});
var _mmg = null;
var editIndex = undefined;
var entryCardCost = function(){
    return{
        init: function () {
            _mmg = $('#dg').datagrid({
                url: '/business/entryCardCostPage',
                method: 'post',
                rownumbers: true,
                striped: true,
                nowrap: true,
                pageList: [25, 30, 35],
                idField: 'id', //主键
                onClickRow: 'onClickRow',
                columns: [
                    [
                        {field: 'ck', checkbox: true},
                        {field: 'id', title: 'id', hidden: true},
                        {field: 'costName', title: '费用名称', width: 100},
                        {field: 'price', title: '价格/元', width: 60},
                        {field: 'criterion', title: '收费标准/人', width: 70},
                        {
                             field: 'operation',
                             title: '操作',
                             width: 70,
                             type: 'String',
                             formatter: function (val, item, rowIndex) {
                                      return '<span><a href="#" onclick="entryCardCost.detail(\''+ item.Id +'\')"><span style="color:blue;">修改</span></a></span>';
                             }
                             },
                    ]
                ],


            }).datagrid("clientPaging");
        },


        //咨询详情
        detail: function (Id) {
            $.post('/contact/consultDetail', {Id: Id}, function (result) {

                if (result != null) {
                    if (result["rows"][0]["Replycontent"]!=''&& result["rows"][0]["Replycontent"]!=null){
                        $("#Replycontent").attr("readonly", "readonly");
                    }
                    $("#Protype").val(result["rows"][0]["Protype"]);
                    $("#Consulttime").val(result["rows"][0]["Consulttime"]);
                    $("#Consultcontent").val(result["rows"][0]["Consultcontent"]);
                    $("#Replycontent").val(result["rows"][0]["Replycontent"]);

                }
            }, 'json');

            $('#w').window('open');
        },

        //新增_弹出框
        addPopu: function () {
            $('#w').window('open');
        },
        //关闭弹出框
        closePopu: function () {
            $('#w').window('close');
            window.location.reload();
        },

        //跳转到  回收站列表
        Recycle: function () {
            window.location.href = '/marketing/activityManageRecycle';
        },
        //保存操作
        save: function () {
            var Replycontent= $("#Replycontent").val();
            var chackedItem = $('#dg').datagrid('getChecked');
            var Id=chackedItem[0]['Id']

            var parmas={Replycontent:Replycontent,Id:Id}

            $.ajax({
                type: 'POST',
                url: '/contact/consultReplycontent',
                dataType: 'json',
                data: parmas,
                success: function (result) {
                    if (result['info'] == '1') {
                        alert("回复成功！")
                        consultManage.closePopu();
                        window.location.reload();
                    } else {
                        alert("回复失败！")
                    }
                }
            })

        },

        //活动加入回收站
        recycle: function (Id) {
            $.messager.confirm('确认', '确定要加入回收站？', function (r) {
                if (r) {
                    $.ajax({
                        type: 'POST',
                        url: '/marketing/recycleactivitybyid',
                        data: 'Id=' + Id,
                        success: function (result) {
                            if (result['info'] == '1') {
                                alert("加入回收站成功！")
                                window.location.reload();
                                return;
                            } else {
                                alert('加入回收站失败！');
                                return;
                            }
                        }
                    })
                }
            });



        },

    }

}
();

